package com.it.base.thread.aqs.imp.aqs;

public class Test {
    private int trick=5;
    private MyAQSlock myAQSlock  = new MyAQSlock();
    public void shopping(){
        myAQSlock.lock();
        if (trick >0){
            try {
                Thread.sleep(10L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            trick = trick -1;
            System.out.println("余票 trick = "+trick);
        }else {
            System.out.println("秒杀失败，余票 trick = "+trick);
        }
        myAQSlock.unlock();
    }

    public static void main(String[] args) {
        Test test = new Test();
        for (int i=1;i<100;i++){
            Thread thread = new Thread(()->test.shopping());
            thread.start();
        }

    }
}
